
function init(){
    treetable= $("#treeTable").treeTable({
        url:base+"/area/view/list",
        column: 1,
        columns:[
            {field:"name",title:"名称",width:"130",align:"center"},
            {field:"code",title:"编码",align:"center",width:"130"},
            {field:"description",title:"描述",align:"center",width:"130"},
            {field:"isEnabled",title:"状态",align:"center",width:"130",formatter:function (rowData,value){
                return value=='1'?"正常":"禁用";
            }},
            {field:"id",title:"操作",width:"180",align:"center",formatter:function(rowData,value){
                return "<a href='javascript:void(0)' onclick=doEdit(\""+value+"\")><span class='btn btn-sm purple'>编辑</span></a>" +
                    "<a href='javascript:void(0)' onclick='doDelete(\""+value+"\")'><span class='btn btn-sm btn-danger'>删除</span></a>" +
                    "<a href='javascript:void(0)' onclick='doAdd(\""+value+"\")'><span class='btn btn-sm btn-primary'>添加下级</span></a>";
            }}
        ]
    });
}



function doEdit(id) {
    var url = base+ "/area/uc/edit?id=" + id + "&type=edit";
    window.location.href=url;
}

function doAdd(id) {
    var url =base+ "/area/uc/edit?id=" + id + "&type=add";
    window.location.href=url;
}


 function doSubmit(type) {
     if (!formCheck().form()) {
         return;
     }
     var url;
     if ("add" == type) {
         url = base + "/area/sk/insert";
     } else {
         url = base + "/area/uc/update";
     }
     $.post(url, $("#editForm").serialize(), function (data) {
         $.messager.alert0({selector: "#editAlert", type: data.code, html: data.message});
         if (data && data.code == 'SUCCESS') {
             tools.goto(base + "/area/view/index", 500);
         }
     }, "json");
 }

/**
 *删除
 */
function doDelete(id) {
    if (!id) {
        $.messager.alert("请选择需要删除的数据项");
        return;
    }
    var childs = $('#' + id).attr("hasChild");
    if ("true" == childs) {
        $.messager.alert("请先删除下级数据");
        return;
    }
    var url =base+"/area/dh/delete";
    $.messager.confirm("你确定要删除选中的记录吗?", function (ck) {
        if(ck){
            var ary = [];
            ary.push(id);
            $.post(url, {ids: ary}, function (data) {
                $.messager.alert0({selector: "#indexAlert", type: data.code, html: data.message});
                if (data && data.code == 'SUCCESS') {
                    treetable.reload();
                }
            });


        }})

}

/**查询*/
function doSearch(){
    var name=$("input[name=name]").val();
    var isEnabled=$("select[name=isEnabled]").val();
    var obj={"name":name,"isEnabled":isEnabled};
    treetable.params=obj;
    treetable.reload();

}


function formCheck() {
    return $('#editForm').validate({
        rules: {
            name: {
                maxlength:[24],
                required: true
            },
            sort: {
                digits:true,
                maxlength:[8],
                required: true
            },
            code: {
                maxlength:[6],
                required: true
            }
        }
    });
}


